<?php
class Pageley_Commerce_Command_AddInfoToOrder extends Pageley_Controller_Command_TransactionalRead {

	protected function executeInternal() {
		$order = $this->getSession()->get(Pageley_Commerce_Session::ORDER);
	    if($order === null || $order->get("orderItems") === null || $order->get("orderItems")->isEmpty()) {
            throw new Pageley_Domain_Exception(new Pageley_I18n_Message("error.commerce.checkOutEmptyOrder"));
        }
        $customer = $this->getSession()->get(Pageley_Commerce_Session::CUSTOMER);
        if($customer === null) {
        	throw new Pageley_Domain_Exception(new Pageley_I18n_Message("error.commerce.notLoggedIn"));
        }
        $serializer = Pageley_Serializer_Format::$HTTP->getSerializer();
        $serializer->deserializeInto($this->getProperties(), $order);
        $order->set("customer", $customer);
        $order->set("amountPayed", new Pageley_Basic_Domain_Money(Pageley_Basic_Domain_Currency::$EUR, 0));
        $order->set("ipAddress", $this->getClientAddress());
	}
}